package butines.core.game.graph;

public class Edge <NodeType extends Node<?>> {

	private NodeType from;
	private NodeType to;
	private double cost;
	
	public Edge() {
		
	}
		
	public Edge(NodeType from, NodeType to, double cost) {
		if (from == null) {
			throw new IllegalArgumentException("from is null");
		}
		if (to == null) {
			throw new IllegalArgumentException("to is null");
		}
		if (cost < 0) {
			throw new IllegalArgumentException("cost can not be negative");
		}
		this.from = from;
		this.to = to;
		this.cost = cost;
	}

	public NodeType getFrom() {
		return from;
	}

	public void setFrom(NodeType from) {
		this.from = from;
	}

	public NodeType getTo() {
		return to;
	}

	public void setTo(NodeType to) {
		this.to = to;
	}

	public double getCost() {
		return cost;
	}

	public void setCost(double cost) {
		if (cost < 0) {
			throw new IllegalArgumentException("cost can not be negative");
		}
		this.cost = cost;
	}
	
	public void remove() {
		from.removeEdge(to);
		to = null;
		from = null;
	}
	
	public String toString() {
		return "[ " + from.getId() + " - " + to.getId() + " ]";
	}

}
